//
//  FGMessagesViewController.h
//  FGChatKit
//
//  Created by Henry on 2021/5/8.
//

#import <UIKit/UIKit.h>
#import "FGKeyboardView.h"
#import "FGNoticeView.h"
#import "FGTextMessageCell.h"
#import "FGSystemMessageCell.h"
#import "FGImageMessageCell.h"
#import "FGVoiceMessageCell.h"
#import "FGVideoMessageCell.h"
#import "FGFaceMessageCell.h"
#import "FGFileMessageCell.h"
#import "FGTemplateMessageCell.h"

@class FGMessagesViewController;

NS_ASSUME_NONNULL_BEGIN

@protocol FGMessagesViewControllerDelegate <NSObject>

@optional

/// 长按消息是否弹出menu
- (BOOL)messageController:(FGMessagesViewController *)controller willShowMenuInCell:(FGMessageCell *)view;

/// 配置长按弹出的UIMenu菜单
- (NSArray <NSString *> *)messageController:(FGMessagesViewController *)controller menuItemIncell:(FGMessageCell *)cell;

/// 点击UIMenu菜单
- (void)messageController:(FGMessagesViewController *)controller onSelectMenu:(NSString *)title msg:(FGMessageCellData *)msg;


/// 点击消息头像
- (void)messageController:(FGMessagesViewController *)controller onSelectMessageAvatar:(FGMessageCell *)cell;

/// 点击消息内容
- (void)messageController:(FGMessagesViewController *)controller onSelectMessageContent:(FGMessageCell *)cell;

/// 点击keybooard更多
- (void)messageController:(FGMessagesViewController *)controller onSelectMoreItem:(FGKeyboardMoreItem *)item;

/// 点击FGNoticeView Title
- (void)messageController:(FGMessagesViewController *)controller noticeView:(FGNoticeView *)noticeView clickTitle:(NSString *)title;

/// 图片消息，图片下载完成
- (void)messageController:(FGMessagesViewController *)controller imageDownloadComplete:(FGMessageCell *)cell;

/// 表单提交
- (void)messageController:(FGMessagesViewController *)controller submitFrom:(NSArray *)fromArr;

/**
 templateDict格式：
 {
     "operationType":1,
     "content":"",
     "id":113,
     "isRecommend":true,
     "title":"账号无法登录",
     "updateTime":"2022-10-26 09:22:22",
     "tagId":128,
     "createTime":"2022-10-26 09:22:22",
     "url":"https:\/\/www.cnblogs.com\/zhaoxiaobei\/p\/9283875.html"
 }
 */
/// 表点击了模板消息上的Cell
- (void)messageController:(FGMessagesViewController *)controller didSelectedTemplateMessageCell:(NSDictionary *)templateDict;

@end

@interface FGMessagesViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, weak) id<FGMessagesViewControllerDelegate> delegate;

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) FGKeyboardView *keyboardView;
@property (nonatomic, strong) FGNoticeView *noticeView;


@property (nonatomic, strong) NSMutableArray *dataArray;

@property (nonatomic, copy) NSString *conversationId;


/// 消息时间间隔（300秒）
@property (nonatomic, assign) NSInteger messageTimeInterval;

/// 发送者
@property (nonatomic, copy) NSString *senderId;
@property (nonatomic, copy) NSString *senderName;



- (void)loadMessage:(FGMessageCellData *)msg complation:(void(^)(BOOL status, NSArray *msgs))complation;

- (void)sendMessage:(FGMessageCellData *)msg complation:(void(^)(BOOL status, FGMessageCellData *msg))complation;
                                                         
- (void)setMoreItem:(NSMutableArray <FGKeyboardMoreItem *> *)items;


/// 配置布局，size改变时
- (void)configLayout:(CGSize)size;
/// 收起键盘
- (void)hiddenKeyboard;
/// 是否展示时间提示
- (BOOL)showTimeFrom:(NSString *)time;
- (void)showMessageTimeWithData:(FGMessageCellData *)data;
/// 改变消息状态
- (void)changeMsg:(FGMessageCellData *)msg status:(FGMsgStatus)status;
/// 滚动到底部
- (void)scrollToBottom:(BOOL)animate;
/// 更新TableView TopInset
- (void)updateTableViewTopInset:(CGFloat)top;
/// 更新TableView BottomInset
- (void)updateTableViewBottomInset:(CGFloat)bottom;

/// 接受消息
- (void)acceptMessages:(NSArray<FGMessageCellData *> *)msgs;
/// 发送消息
- (void)sendMessage:(FGMessageCellData *)msg;
- (void)sendMessageText:(NSString *)text;
- (void)sendMessageImage:(UIImage *)image;
- (void)sendMessageVoice:(NSDictionary *)voice;
- (void)sendMessageSystem:(NSString *)system;

- (void)onDelete;

/// 撤回消息
/// @param text 显示的内容
/// @param msgId 消息ID
- (void)onRevoke:(NSString *)text msgId:(NSString *)msgId;
/// 没有消息ID，取值menuMsg，可用于点击UIMenu时。点击后menuMsg=nil
- (void)onRevoke:(nullable NSString *)text;

- (NSIndexPath *)indexPathOfMsg:(FGMessageCellData *)msg;
- (NSIndexPath *)indexPathOfMsgId:(NSString *)msgId;
- (FGMessageCellData *)dataOfUUID:(NSString *)uuid;

- (void)showImageMessage:(FGImageMessageCell *)cell;

@end

NS_ASSUME_NONNULL_END
